package com.jxzyk.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.core.util.L;
import com.core.util.T;
import com.core.util.UiTools;
import com.jxzyk.entity.tree.Material;
import com.jxzyk.model.MainActivity;
import com.jxzyk.model.PhotoActivity;
import com.jxzyk.model.VideoActivity;
import com.jxzyk.model.WebActivity;
import com.jxzyk.model.course.CourseActivity;
import com.jxzyk.util.BitmapHelp;
import com.lidroid.xutils.BitmapUtils;

public class OutlineAdapter extends VPagerAdapter {
	private BitmapUtils bitmapUtils;
	private CourseActivity activity;
	public static String TAG = "OutlineAdapter";

	public OutlineAdapter(CourseActivity activity) {
		this.activity = activity;
	}

	@Override
	public void setContext(Context context) {
		super.setContext(context);
		bitmapUtils = BitmapHelp.getBitmapUtils(context);
	}

	@Override
	public View getViewGroup(ViewGroup container, int position) {
		final Material material = (Material) getLists().get(position);
		ImageView img = new ImageView(getContext());
		container.addView(img);
		final String[] url = material.getMaterial_content().split(",");
		bitmapUtils.display(img, url[0]);
		img.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Bundle bundle = new Bundle();
				String type = material.getMaterial_type();
				L.d(type);
				if (type.equals("图片")) {
					bundle.putStringArray(OutlineAdapter.TAG, url);
					activity.showActivity(PhotoActivity.class, bundle);
				} else {
					if (url.length > 1) {
						String playUrl = url[1];
						bundle.putString(OutlineAdapter.TAG, playUrl);
						if (playUrl.contains(".swf")) {
							activity.showActivity(playUrl);
						} else if (playUrl.contains(".mp4")
								|| playUrl.contains(".wmv")) {
							activity.showActivity(VideoActivity.class, bundle);
						}
					}
				}
			}
		});
		return img;
	}

	@Override
	public View getView(View container, int position) {
		return null;
	}

}
